package com.wang.controller;

import com.wang.entity.Employee;
import com.wang.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;

/**
 * @Classname MailController
 * @Description TODO
 * @Date 2024/5/29 9:36
 * @Created by pc
 */
@RestController
public class MailController {
    @Autowired
    private MailService mailService;

    @GetMapping("/simple")
    public String sendSimpleMail() {
        mailService.sendSimpleMail("1978982405@qq.com", "邮件标题", "龙哥学的真不错");
        return "success";
    }

    @GetMapping("/html")
    public String sendHtmlMail() {
        mailService.sendHtmlMail("1978982405@qq.com", "邮件主题",
                "<h1>邮件主题</h1><br/><p><font color='red'>邮件内容</font></p>");
        return "success";
    }

    @GetMapping("/attachment")
    public String sendAttachmentMail() {
        mailService.sendAttachmentsMail("1978982405@qq.com",
                "主题:带附件的邮件", "有附件的邮件,不要错过哦...", "static/xingteng.jpg");
        return "success";
    }
    @PostMapping("/model")
    public String sendModelMail(@RequestBody Employee employee) throws MessagingException {
        mailService.sendModelMail("1978982405@qq.com", "主题:新员工入职欢迎邮件--模板邮件", "mail.ftl", employee);
        return "success";
    }
}
